<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>库存查询</title>
 	<link href="../resources/css/ligerui-all.css" rel="stylesheet" type="text/css" /> 
 	<link href="../resources/css/ligerui-icons.css" rel="stylesheet" type="text/css" /> 
	<script src="../resources/js/jquery-1.9.1.min.js" type="text/javascript"></script>
	<script src="../resources/js/ligerui.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    	$(function ()
        {
            /*设置所有ajax为同步提交*/
    		$.ajaxSetup({ 
    			  async: false 
    			  }); 
			  /*库存数据*/
	              window['g'] = $("#isr").ligerGrid({
	                	checkbox: true,
	                    columns: [
	                    { display: '物料编码', name: 'inventoryNO', width: 120, isSort: false},
	                    { display: '物料名称', name: 'inventoryName', width: 100, isSort: false},
	    				        { display: '初期库存', name: 'previousMonthStockAmount', width: 100, isSort: false},
	    				        { display: '最近入库', name: 'warehousingAmount', width: 100, isSort: false },
	    				        { display: '最近出库', name: 'deliveryAmount', width: 100, isSort: false },
	    				        { display: '单位', name: 'unit', width: 100, isSort: false},
	    				        { display: '单位成本', name: 'unitPrice', width: 100, isSort: false},
	    				        { display: '物料类型', name: 'materielCostCategory', width: 100, isSort: false},
	    				        { display: '总额', name: 'priceAmount', width: 100, isSort: false},
	    				        { display: '当前库存', name: 'inventoryAmount', width: 100, isSort: false }
	                    ], //width: 1000,
	                    url : "list",
	                    width: '99.9%',
	                    pageSizeOptions: [3, 5, 7, 10],
	                    rownumbers:true
	                 });

	               /*为form增加样式*/
	              $("form").ligerForm();

	               /*工具条*/
	                $("#toolBar").ligerToolBar( {
	                    items : [
									{ text: '增加物料', click: add, icon: 'add' },
									{line: true},
									{ text: '修改物料', click: update, icon: 'edit' },
									{line: true},
									{ text: '删除物料', click: del, icon: 'busy' },
									{line: true},
									{ text: '导入', click: upload, icon: 'back' },
									{line: true},
									{ text: '导出', click: download, icon: 'up' },
									{line: true},
									{ text: '模板下载', click: template, icon: 'attibutes' },
								]
						
	                });

	          /*条件查询*/
			$("#Button1").click(function() {
				var param = $("#form0").serialize(); 
				var url = "list?" + param;
				$.post(url, 
						{'page':1, 'pagesize': 10}
				  , function(data){
						g.loadData(data);
						g.setOptions({'url': url, 'pageSizeOptions': [3, 5, 7, 10], 'page':1, 'pagesize': 10} );
					 });
				});
        });

    	/*增加物料信息*/
    	var add = function() {
        	loadDirctionary();
        	 $("#inventoryNO").val("BH" + new Date().getTime());
        	 $("#form1").prop("action", "add");
        	$.ligerDialog.open({ target: $("#frm"), width: 650, title: '增加物料信息' });
         };
         
		/*修改物料信息*/
         var update = function() {
        	 var s = g.getSelectedRows();
        	 if(s.length > 1) {
        		 $.ligerDialog.warn('修改信息不允许多选!');
             }else if(s.length == 0) {
            	 $.ligerDialog.warn('请选择一条记录!');
             }else{
            	    loadDirctionary();
            	     
	                 $("#inventoryNO").val(s[0].inventoryNO);
	                 $("#inventoryName").val(s[0].inventoryName);
	                 var unitval = s[0].unit;
	                 $("#unit").val(unitval);
	                 $("#unitPrice").val(s[0].unitPrice);
	                 $("#materielCostCategory").val([s[0].materielCostCategory]);
	                 $("#form1").prop("action", "update");
	                 $("<input type='hidden' name='inventoryID' id='inventoryID' value=" + s[0].inventoryID + ">").appendTo($("#form1"));
	        		$.ligerDialog.open({ target: $("#frm"), width: 650, title: '修改物料信息' });
             };

           };

           /*删除物料信息*/
           var del = function() {
           	var s = g.getSelectedRows();
           	if(s.length!=0) {
           	$.ligerDialog.confirm('您真的要删除所选择的信息吗?', function (yes) { 
   	              if(yes) {
   	        	   var p = new Array();
   	        	   for(var i=0; i<s.length; i++) {
   	   	        	   if(s[i].inventoryAmount==0) {
   	            	  	 p.push(s[i].inventoryID);
   	   	        	   }else {
   	   	        	      $.ligerDialog.success('不能删除存在库存的物料信息！<p style="color:red; font-weight: bold;">当前库存:' + s[i].inventoryAmount + "</span>");
   	   	        	      return false;
   	   	   	           }
   	               }
   	        	   var arrs = JSON.stringify(p);
   	        		$.get("/baohua/inventory/del/" + arrs, function(data){
   	            		var mess = eval(data);
   	            		  switch (mess)
   	                      {
   	                          case "success":
   	                        	  g.loadData(); 
   	                              $.ligerDialog.success('删除成功！');
   	                              break;
   	                          case "systemerror":
   	                              $.ligerDialog.warn('系统出现错误！');
   	                              break;
   	                          case "error":
   	                              $.ligerDialog.error('供应商不存在, 不能删除！');
   	                              break;
   	                      }
   	            	}); 
   	            	}
           	});
           	}else {
           		$.ligerDialog.warn('请选择一条记录!');
                }
              };

              var upload = function() {
                  alert("ddd");
              }

              var download = function() {
           	   var s = g.getSelectedRows();
           	   var arrs = new Array();
           	   $(s).each(function(i){
               	   arrs.push(s[i].inventoryNO);
                  });
                  var param = arrs.join(",");
                  $("#param").val(param);
                  $("#form2").submit();
              }

              var template = function() {
                 window.location.href = "export";
              }

          /*从数据字典中加载数据*/
         function loadDirctionary() {
      	   var promise = $.when($.get("/baohua/materiel/loadDirctionary/26"
      	      	   ),$.get("/baohua/materiel/loadDirctionary/31"));
            promise.done(function(data1, data2) {
          	   var units = data1[0];
          	   var categorys = data2[0];
          	   var unit = "<select name='unit' id='unit' ltype='select' style='width:182px'>";
          	   $(units).each(function(i) {
          		   unit = unit + "<option value=" + units[i] + ">" + units[i] + "</option>"
                 });
                 unit = unit + "</select>";
          	   $("#my_materielUnit").html(unit);
          	   var category = "<select name='materielCostCategory' ltype='select' id='materielCostCategory' style='width:182px'>";
          	   $(categorys).each(function(i) {
              	   category = category + "<option value=" + categorys[i] + ">"+ categorys[i] +"</option>";
              	});
          	   category = category + "</select>";
          	   $("#my_materielCostCategory").html(category);
          	 $("#unit").ligerComboBox({'width':'180'});
    	     $("#materielCostCategory").ligerComboBox({'width':'180'});
             });
         }

        
    </script>
    <style type="text/css">
		#isr #toolBar { margin-left:5px;}
        .l-table-edit-td{ padding:3px;}
        .l-button-submit,.l-button-reset{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
        .l-verify-tip{ left:230px; top:120px;}
</style>
</head>

<body>
 <!-- 1.导航条 -->
   <span style=" margin: 5px 10px; display: block; font-weight: bold;">宝华茶餐厅 > 库存管理 > 库存查询</span>
 <!-- 2.查询条件 --> 
   <div id="isearch" style="width:100%; margin-bottom: 5px;">
	  <form name="form0" method="post"  id="form0">
        <table cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td align="right" class="l-table-edit-td" width="11%">物料编码:</td>
                <td align="left" class="l-table-edit-td" style="width:23px">
                   <input name="inventoryNO" type="text" ltype="text" id="i_inventoryNO"/>
                </td>
                
                <td align="right" class="l-table-edit-td" width="10%">物料名称:</td>
                <td align="left" class="l-table-edit-td" style="width:23px"><input name="inventoryName" type="text" ltype="text" id="i_inventoryName"/></td>
            </tr>
             <tr>
                <td align="right" class="l-table-edit-td" width="11%">总额:</td>
                <td align="left" class="l-table-edit-td" style="width:23px">
                   <input name="pre_priceAmount" type="text" ltype="spinner"  id="i_pre_priceAmount"/> 至 
                   <input name="af_priceAmount" type="text" ltype="spinner" id="i_af_priceAmount"/>
                </td>
                
                <td align="right" class="l-table-edit-td" width="10%">当前库存:</td>
                <td align="left" class="l-table-edit-td">
                	<input name="pre_inventoryAmount" ltype="spinner"  type="text"   id="i_pre_inventoryAmount"/> 至
                    <input name="af_inventoryAmount" ltype="spinner" type="text"  id="i_af_inventoryAmount"/>
                </td>
            </tr>
             <tr>
                 <td colspan="3">&nbsp;</td>
                 <td>
	                 <input type="button" value="查询" id="Button1" class="l-button l-button-submit" /> 
		             <input type="reset" value="重置" class="l-button l-button-reset"/>
		         </td>
            </tr>
        </table>
    </form>
    </div>
 <!-- 3.g工具条 -->  
    <div id="toolBar"></div>
 <!-- 4.库存列表 -->   
	<div id="isr"></div>
  <div id="frm" style="width:600px; margin:3px; display:none;">
     	<form name="form1" method="post"  id="form1">
        <table cellpadding="0" cellspacing="0" width="600px">
            <tr>
                <td align="right" class="l-table-edit-td" width="100px">物料编码:</td>
                <td align="left" class="l-table-edit-td" style="width:160px"><input name="inventoryNO" type="text" ltype="text" id="inventoryNO" validate="{required:true,minlength:3,maxlength:10}"/></td>
                <td align="left" width="40px"></td>
                
                <td align="right" class="l-table-edit-td" width="100">物料名称:</td>
                <td align="left" class="l-table-edit-td" style="width:160px"><input name="inventoryName" type="text" ltype="text"  id="inventoryName"/></td>
                <td align="left" width="40px"></td>
            </tr>
             
            <tr>
                <td align="right" class="l-table-edit-td" width="100px">物料单位:</td>
                <td align="left" class="l-table-edit-td" style="width:160px" id="my_materielUnit">
                </td>
                <td align="left" width="40px"></td>
                
                <td align="right" class="l-table-edit-td" width="100px">单位成本:</td>
                <td align="left" class="l-table-edit-td" style="width:160px"><input name="unitPrice" type="text" id="unitPrice" ltype="spinner"></td>
                <td align="left" width="40px"></td>
            </tr>
            
              <tr>
                 <td align="right" class="l-table-edit-td" width="100px">物料类型:</td>
                <td align="left" class="l-table-edit-td" id="my_materielCostCategory"> 
                </td>
                <td align="left" width="40px"></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr> 
                 
            <tr>
               <td colspan="4">&nbsp;</td>
               <td align="right">
                  <input type="submit" value="提交"  class="l-button l-button-submit" /> 
				  <input type="reset" value="重置" class="l-button l-button-reset"/>
               </td>
                <td align="left" width="40px"></td>
            </tr>
        </table>
    </form>
    </div>
    <form action="export" method="post" id="form2">
    	<input type="hidden" name="param" id="param">
    </form>
</body>

</html>